<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.3.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/myblog/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/myblog/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/myblog/images/favicon-16x16.png">
  <link rel="mask-icon" href="/myblog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/myblog/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic%7CRoboto+Slab:300,300italic,400,400italic,700,700italic%7CNoto+Serif+SC:300,300italic,400,400italic,700,700italic%7CAmita:300,300italic,400,400italic,700,700italic%7CMontserrat:300,300italic,400,400italic,700,700italic%7CPT+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha256-AbA177XfpSnFEvgpYu1jMygiLabzPCJCRIBtR5jGc0k=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wang-chen1119.gitee.io","root":"/myblog/","images":"/myblog/images","scheme":"Pisces","darkmode":false,"version":"8.13.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":true,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}}</script><script src="/myblog/js/config.js"></script>

    <meta name="description" content="centos7 搭建redis一主二从三哨兵安装redis下载安装包123wget https:&#x2F;&#x2F;download.redis.io&#x2F;releases&#x2F;redis-5.0.14.tar.gz#解压tar -xvf  redis-5.0.14.tar.gz  如果需要其他版本的redis可以到官网进行下载">
<meta property="og:type" content="blog">
<meta property="og:title" content="centos7 搭建redis一主二从三哨兵">
<meta property="og:url" content="http://wang-chen1119.gitee.io/myblog/2022/10/28/redis%E4%B8%80%E4%B8%BB%E4%BA%8C%E4%BB%8E%E4%B8%89%E5%93%A8%E5%85%B5%E6%90%AD%E5%BB%BA/index.html">
<meta property="og:site_name" content="Yorn&#39;s Notes">
<meta property="og:description" content="centos7 搭建redis一主二从三哨兵安装redis下载安装包123wget https:&#x2F;&#x2F;download.redis.io&#x2F;releases&#x2F;redis-5.0.14.tar.gz#解压tar -xvf  redis-5.0.14.tar.gz  如果需要其他版本的redis可以到官网进行下载">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104192039988.png">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104192311387.png">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104195459912.png">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104195908759.png">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104200008012.png">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104200053229.png">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104200246596.png">
<meta property="og:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104200347169.png">
<meta property="article:published_time" content="2022-10-28T08:47:57.049Z">
<meta property="article:modified_time" content="2022-10-28T08:47:36.716Z">
<meta property="article:author" content="yorn">
<meta property="article:tag" content="redis">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://wang-chen1119.gitee.io/AppData/Roaming/Typora/typora-user-images/image-20220104192039988.png">


<link rel="canonical" href="http://wang-chen1119.gitee.io/myblog/2022/10/28/redis%E4%B8%80%E4%B8%BB%E4%BA%8C%E4%BB%8E%E4%B8%89%E5%93%A8%E5%85%B5%E6%90%AD%E5%BB%BA/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://wang-chen1119.gitee.io/myblog/2022/10/28/redis%E4%B8%80%E4%B8%BB%E4%BA%8C%E4%BB%8E%E4%B8%89%E5%93%A8%E5%85%B5%E6%90%AD%E5%BB%BA/","path":"2022/10/28/redis一主二从三哨兵搭建/","title":"centos7 搭建redis一主二从三哨兵"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>centos7 搭建redis一主二从三哨兵 | Yorn's Notes</title>
  






  <noscript>
    <link rel="stylesheet" href="/myblog/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/myblog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Yorn's Notes</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-首页"><a href="/myblog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-关于"><a href="/myblog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-标签"><a href="/myblog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-分类"><a href="/myblog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#centos7-%E6%90%AD%E5%BB%BAredis%E4%B8%80%E4%B8%BB%E4%BA%8C%E4%BB%8E%E4%B8%89%E5%93%A8%E5%85%B5"><span class="nav-number">1.</span> <span class="nav-text">centos7 搭建redis一主二从三哨兵</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AE%89%E8%A3%85redis"><span class="nav-number">1.1.</span> <span class="nav-text">安装redis</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85%E5%8C%85"><span class="nav-number">1.1.1.</span> <span class="nav-text">下载安装包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BC%96%E8%AF%91"><span class="nav-number">1.1.2.</span> <span class="nav-text">编译</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%89%A7%E8%A1%8C%E8%84%9A%E6%9C%AC%E5%A4%84%E7%90%86"><span class="nav-number">1.1.3.</span> <span class="nav-text">执行脚本处理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-number">1.1.4.</span> <span class="nav-text">修改配置文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%8E%A8%E8%8D%90%E5%90%AF%E5%8A%A8%E6%96%B9%E5%BC%8F"><span class="nav-number">1.1.5.</span> <span class="nav-text">推荐启动方式</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AE%E4%B8%80%E4%B8%BB%E4%BA%8C%E4%BB%8E%E4%B8%89%E5%93%A8%E5%85%B5"><span class="nav-number">1.2.</span> <span class="nav-text">配置一主二从三哨兵</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%B5%84%E6%BA%90%E5%87%86%E5%A4%87"><span class="nav-number">1.2.1.</span> <span class="nav-text">资源准备</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E7%9B%AE%E5%BD%95"><span class="nav-number">1.2.1.1.</span> <span class="nav-text">创建目录</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%A4%8D%E5%88%B6%E4%B8%89%E4%BB%BDredis%E5%88%B0%E6%AD%A4%E7%9B%AE%E5%BD%95%EF%BC%88%E5%91%BD%E5%90%8D%E6%8C%89%E8%87%AA%E5%B7%B1%E9%9C%80%E6%B1%82%E6%9D%A5%E5%8D%B3%E5%8F%AF%EF%BC%89"><span class="nav-number">1.2.1.2.</span> <span class="nav-text">复制三份redis到此目录（命名按自己需求来即可）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9redis-conf%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-number">1.2.1.3.</span> <span class="nav-text">修改redis.conf配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9sentinel-conf%E9%85%8D%E7%BD%AE"><span class="nav-number">1.2.1.4.</span> <span class="nav-text">修改sentinel.conf配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%90%AF%E5%8A%A8%E6%B5%8B%E8%AF%95"><span class="nav-number">1.2.1.5.</span> <span class="nav-text">启动测试</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B5%8B%E8%AF%95"><span class="nav-number">1.2.2.</span> <span class="nav-text">测试</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="yorn"
      src="/myblog/uploads/head.jpg">
  <p class="site-author-name" itemprop="name">yorn</p>
  <div class="site-description" itemprop="description">足够专注才能成功</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/myblog/archives/">
          <span class="site-state-item-count">53</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/myblog/categories/">
        <span class="site-state-item-count">13</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/myblog/tags/">
        <span class="site-state-item-count">19</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wang-chen1119" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wang-chen1119" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:w1905989051@gmail.com" title="E-Mail → mailto:w1905989051@gmail.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license site-overview-item animated" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="https://cdnjs.cloudflare.com/ajax/libs/creativecommons-vocabulary/2020.11.3/assets/license_badges/small/by_nc_sa.svg" alt="Creative Commons"></a>
  </div>


  <div class="links-of-blogroll site-overview-item animated">
    <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://blog.csdn.net/qq_51088445" title="https:&#x2F;&#x2F;blog.csdn.net&#x2F;qq_51088445" rel="noopener" target="_blank">CSDN</a>
        </li>
    </ul>
  </div>

        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <a href="https://github.com/wang-chen1119" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://wang-chen1119.gitee.io/myblog/2022/10/28/redis%E4%B8%80%E4%B8%BB%E4%BA%8C%E4%BB%8E%E4%B8%89%E5%93%A8%E5%85%B5%E6%90%AD%E5%BB%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/myblog/uploads/head.jpg">
      <meta itemprop="name" content="yorn">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Yorn's Notes">
      <meta itemprop="description" content="足够专注才能成功">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="centos7 搭建redis一主二从三哨兵 | Yorn's Notes">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          centos7 搭建redis一主二从三哨兵
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>
      

      <time title="创建时间：2022-10-28 16:47:57 / 修改时间：16:47:36" itemprop="dateCreated datePublished" datetime="2022-10-28T16:47:57+08:00">2022-10-28</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/myblog/categories/redis/" itemprop="url" rel="index"><span itemprop="name">redis</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>1.7k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>2 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="centos7-搭建redis一主二从三哨兵"><a href="#centos7-搭建redis一主二从三哨兵" class="headerlink" title="centos7 搭建redis一主二从三哨兵"></a>centos7 搭建redis一主二从三哨兵</h1><h2 id="安装redis"><a href="#安装redis" class="headerlink" title="安装redis"></a>安装redis</h2><h3 id="下载安装包"><a href="#下载安装包" class="headerlink" title="下载安装包"></a>下载安装包</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">wget https://download.redis.io/releases/redis-5.0.14.tar.gz</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">解压</span></span><br><span class="line">tar -xvf  redis-5.0.14.tar.gz</span><br></pre></td></tr></table></figure>

<p>如果需要其他版本的redis可以到官网进行下载</p>
<h3 id="编译"><a href="#编译" class="headerlink" title="编译"></a>编译</h3><p>进入根目录，看到Makefile文件</p>
<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104192039988.png" alt="image-20220104192039988"></p>
<p>进行编译</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">安装 gcc</span></span><br><span class="line"> yum install gcc</span><br><span class="line"><span class="meta prompt_"> #</span><span class="language-bash">编译  默认make命令编译  =&gt; 如果提示：jemalloc/jemalloc.h: 没有那个文件或目录，make的时候加上MALLOC=libc 参数.</span></span><br><span class="line"> make MALLOC=libc</span><br></pre></td></tr></table></figure>

<h3 id="执行脚本处理"><a href="#执行脚本处理" class="headerlink" title="执行脚本处理"></a>执行脚本处理</h3><p>进入src找到需要的可执行文件，下图中绿色的就是需要的可执行文件</p>
<p>在根目录创建 bin ，将这些文件移入bin</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp mkreleasehdr.sh redis-benchmark redis-check-aof  redis-cli redis-sentinel redis-server  ../bin/</span><br></pre></td></tr></table></figure>





<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104192311387.png" alt="image-20220104192311387"></p>
<p>启动服务命令(不建议)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-server</span><br></pre></td></tr></table></figure>



<p>启动客户端命令</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-cli</span><br></pre></td></tr></table></figure>

<h3 id="修改配置文件"><a href="#修改配置文件" class="headerlink" title="修改配置文件"></a>修改配置文件</h3><p>修改redis.conf文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">找到 :port 6379 修改为</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">建议修改端口 方便测试连接 同时原端口6379容易中挖矿病毒</span></span><br><span class="line"> port xxxx</span><br><span class="line"><span class="meta prompt_"> # </span><span class="language-bash">找到 requirepass foobared，下一行追加</span></span><br><span class="line"><span class="meta prompt_"> # </span><span class="language-bash">设置密码</span></span><br><span class="line"> requirepass xxxxx</span><br><span class="line"><span class="meta prompt_"> #</span><span class="language-bash">找到<span class="built_in">bind</span>配置 <span class="built_in">bind</span> 127.0.0.1 设置0.0.0.0</span></span><br><span class="line"><span class="meta prompt_"> # </span><span class="language-bash">设置能够连接redis的ip</span></span><br><span class="line"> bind 0.0.0.0</span><br><span class="line"><span class="meta prompt_"> #</span><span class="language-bash">找到 protected-mode <span class="built_in">yes</span> 关闭保护模式</span></span><br><span class="line"> protected-mode no</span><br></pre></td></tr></table></figure>

<h3 id="推荐启动方式"><a href="#推荐启动方式" class="headerlink" title="推荐启动方式"></a>推荐启动方式</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./redis-server redis.conf</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">./redis-cli -p xxx</span><br><span class="line">127.0.0.1:6880&gt; auth 密码</span><br></pre></td></tr></table></figure>

<h2 id="配置一主二从三哨兵"><a href="#配置一主二从三哨兵" class="headerlink" title="配置一主二从三哨兵"></a>配置一主二从三哨兵</h2><h3 id="资源准备"><a href="#资源准备" class="headerlink" title="资源准备"></a>资源准备</h3><h4 id="创建目录"><a href="#创建目录" class="headerlink" title="创建目录"></a>创建目录</h4><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/opt/redis/cluster-sentinel</span><br></pre></td></tr></table></figure>

<h4 id="复制三份redis到此目录（命名按自己需求来即可）"><a href="#复制三份redis到此目录（命名按自己需求来即可）" class="headerlink" title="复制三份redis到此目录（命名按自己需求来即可）"></a>复制三份redis到此目录（命名按自己需求来即可）</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">cd /opt/redis/cluster-sentinel</span><br><span class="line">cp -r /usr/local/redis .</span><br><span class="line">mv redis redis-6880</span><br><span class="line">cp -r redis-6880 redis-6881</span><br><span class="line">cp -r redis-6880 redis-6882</span><br></pre></td></tr></table></figure>

<h4 id="修改redis-conf配置文件"><a href="#修改redis-conf配置文件" class="headerlink" title="修改redis.conf配置文件"></a>修改redis.conf配置文件</h4><ul>
<li>分别修改三个单体应用配置</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">端口 三个不一样的端口</span></span><br><span class="line">port 6880</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">主从复制  初始主节点ip 和  端口  同一台机器127即可</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">replicaof &lt;masterip&gt; &lt;masterport&gt;</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">旧版：<span class="comment"># slaveof &lt;masterip&gt; &lt;masterport&gt;</span></span></span><br><span class="line">replicaof 实际ip 8974</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">主节点密码</span>  </span><br><span class="line">masterauth xxx</span><br></pre></td></tr></table></figure>



<h4 id="修改sentinel-conf配置"><a href="#修改sentinel-conf配置" class="headerlink" title="修改sentinel.conf配置"></a>修改sentinel.conf配置</h4><ul>
<li>分别修改三个单体应用</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">设置守护进程   后台启动，不设置也可以</span></span><br><span class="line">daemonize yes</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">初始主节点 ip 和 端口   ，   2代表大于等于2票即可成为主节点</span></span><br><span class="line">sentinel monitor mymaster 实际ip 8974 2</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">主节点密码</span></span><br><span class="line">sentinel auth-pass mymaster xxx</span><br></pre></td></tr></table></figure>

<h4 id="启动测试"><a href="#启动测试" class="headerlink" title="启动测试"></a>启动测试</h4><p>启动六个中端启动三个节点的redis和sentinel</p>
<p>进入bin目录执行</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动redis服务</span></span><br><span class="line">./redis-server ../redis.conf </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动哨兵服务</span></span><br><span class="line">./redis-sentinel ../sentinel.conf </span><br></pre></td></tr></table></figure>



<h3 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h3><p>使用RedisDesktopManager进行测试</p>
<p>创建三个连接连接三个节点</p>
<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104195459912.png" alt="image-20220104195459912"></p>
<p>此时我们在设置的主节点创建测试</p>
<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104195908759.png" alt="image-20220104195908759"></p>
<p>然后我们去从节点进行查看</p>
<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104200008012.png" alt="image-20220104200008012"></p>
<p>两个从节点都能查看新创建的例子，然后我们进行修改</p>
<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104200053229.png" alt="image-20220104200053229"></p>
<p>我们可以看到从节点只有读权限</p>
<p>然后我们断开主结点的连接,观察哨兵变化</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">127.0.0.1:6882&gt; shutdown SAVE</span><br></pre></td></tr></table></figure>

<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104200246596.png" alt="image-20220104200246596"></p>
<p>主节点失效后，通过投票选出了新的主节点，然后我们再去用6880节点进行修改</p>
<p><img src="/myblog/../../AppData/Roaming/Typora/typora-user-images/image-20220104200347169.png" alt="image-20220104200347169"></p>
<p>修改成功，说明该节点成为了主节点，一主二从三哨兵也就搭建完成了</p>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>yorn
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="http://wang-chen1119.gitee.io/myblog/2022/10/28/redis%E4%B8%80%E4%B8%BB%E4%BA%8C%E4%BB%8E%E4%B8%89%E5%93%A8%E5%85%B5%E6%90%AD%E5%BB%BA/" title="centos7 搭建redis一主二从三哨兵">http://wang-chen1119.gitee.io/myblog/2022/10/28/redis一主二从三哨兵搭建/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/myblog/tags/redis/" rel="tag"><i class="fa fa-tag"></i> redis</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/myblog/2022/10/28/%E6%B5%8F%E8%A7%88%E5%99%A8%E8%BE%93%E5%85%A5%E4%B8%80%E4%B8%AAurl%E5%88%B0%E6%95%B4%E4%B8%AA%E9%A1%B5%E9%9D%A2%E6%98%BE%E7%A4%BA%E5%87%BA%E6%9D%A5%E7%BB%8F%E5%8E%86%E4%BA%86%E5%93%AA%E4%BA%9B%E8%BF%87%E7%A8%8B/" rel="prev" title="浏览器输入一个url到整个页面显示出来经历了哪些过程">
                  <i class="fa fa-chevron-left"></i> 浏览器输入一个url到整个页面显示出来经历了哪些过程
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/myblog/2022/10/28/OAuth2.0%E5%8D%8F%E8%AE%AE/" rel="next" title="OAuth2.0协议">
                  OAuth2.0协议 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yorn</span>
</div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/myblog/js/comments.js"></script><script src="/myblog/js/utils.js"></script><script src="/myblog/js/motion.js"></script><script src="/myblog/js/next-boot.js"></script><script src="/myblog/js/bookmark.js"></script>

  





  





<script src="/myblog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
